package com.example.rdemo.service;

import java.util.Date;
import java.util.List;

import com.example.rdemo.entity.Shop;
import com.example.rdemo.mapper.ShopMapper;
import com.example.rdemo.utils.PageResult;
import com.example.rdemo.utils.PageUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * shopService业务层处理
 * 
 * @author ruoyi
 * @date 2025-04-01
 */
@Service
public class ShopServiceImpl implements ShopService {
    @Autowired
    private ShopMapper shopMapper;

    //查询shop
    @Override
    public Shop selectShopByCid(Long cid)
    {
        return shopMapper.selectShopByCid(cid);
    }

    //查询shop列表
    @Override
    public PageResult selectShopList(Shop shop,int pageNum,int pageSize)
    {
        //调用pageHelper插件
        PageHelper.startPage(pageNum,pageSize);
        List<Shop> list = shopMapper.selectShopList(shop);  //分页数据
        System.out.println(list.size());
        PageInfo<Shop> pageInfo = new PageInfo<>(list);
        PageResult pageResult = PageUtils.getPageResult(pageInfo);
        return pageResult;
    }

    @Override
    public PageResult selectShopGoodsList(Shop shop, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Shop> list = shopMapper.selectShopGoodsList(shop);  //分页数据
        System.out.println(list.size());
        PageInfo<Shop> pageInfo = new PageInfo<>(list);
        PageResult pageResult = PageUtils.getPageResult(pageInfo);
        return pageResult;
    }

    //新增shop
    @Override
    public int insertShop(Shop shop)
    {
        shop.setCreateTime(new Date());
        return shopMapper.insertShop(shop);
    }

    //修改shop
    @Override
    public int updateShop(Shop shop)
    {
        shop.setUpdateTime(new Date());
        return shopMapper.updateShop(shop);
    }

    //批量删除shop
    @Override
    public int deleteShopByCids(Long[] cids)
    {
        return shopMapper.deleteShopByCids(cids);
    }

    //删除shop信息
    @Override
    public int deleteShopByCid(Long cid)
    {
        return shopMapper.deleteShopByCid(cid);
    }
}
